package com.shycloud.mido.member.test;

import cn.hutool.core.collection.ConcurrentHashSet;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * 迁移现有数据(作业)
 *
 * @author Xiaoxing Yu
 * @date 2020/11/19 下午5:04
 **/
public class TransferOriginalTableData {

	//812cae35b3def83088631572a8165e03	测试库我的学生studentId

	public static AtomicInteger atomicInteger = new AtomicInteger(0);

	public static void main(String[] args) {
		ExecutorService transferPool = Executors.newFixedThreadPool(10);
		int startIdx = 2200000;	//2144229
		int step = 1000;
		int loop = 110;

		List<Thread> threadList = new ArrayList<>();
		CountDownLatch latch = new CountDownLatch(loop);
		ConcurrentHashSet<String> sqlSet = new ConcurrentHashSet<>();

		for (int i = 0; i < loop; i++) {
			Thread thread = new TransferThread(
					startIdx + i * step, step, atomicInteger, latch, sqlSet, true, 792238L);
//			Thread thread = new TransferThread(0, 1, atomicInteger);
			transferPool.submit(thread);
			threadList.add(thread);
		}

		try {
			latch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println("haha end!");
		System.out.println(sqlSet.size());

		transferPool.shutdownNow();
}



}
